/*
 ============================================================================
 Name		: BlockPipe.h
 Author	  : spring xu
 Version	 : 1.0
 Copyright   : 
 Description : CBlockPipe declaration
 ============================================================================
 */

#ifndef BLOCKPIPE_H
#define BLOCKPIPE_H

#include <e32base.h>	// For CActive, link against: euser.lib
#include <e32std.h>		// For RTimer, link against: euser.lib

#include "TradeBlockNetwork.h"
#include "ThreadSocket.h"

class CThreadSocket;
class CReqData;
class CBlockPipe : public CActive, public MClientObserver
{
public:
	// Cancel and destroy
	~CBlockPipe();
	static CBlockPipe* Static();

public:
	void StartL();
	
	TInt AppendReq(TAny* pAny, MReqObserver* pObserver, const TDesC8& aPostData);

//MClientObserver
public:
	virtual void ClientEvent(const TDesC& aEventDescription);
	virtual void ClientBodyReceived(const TDesC8& aBodyData);
	virtual void ClientUpdateProgress(const TInt& aPercent);
	virtual void ConnectionOpened();	
	
public:
	TBool Remove(MReqObserver* p);
	
private:
	CBlockPipe();
	void ConstructL();
	
	static CBlockPipe* NewL();
	static CBlockPipe* NewLC();
	
private:
	void RunL();
	void DoCancel();
	TInt RunError(TInt aError);
	
	TInt AppendReq(CReqData* pReq);
private:
	enum TBlockPipeState
	{
	//EUninitialized, // Uninitialized
	//EInitialized, // Initalized
	EBlockPipeStatus_None,
	EBlockPipeStatus_Req,
	EBlockPipeStatus_Resp,
	EError
	// Error condition
	};

private:
	TInt iState; // State of the active object
	RTimer iTimer; // Provides async timing service
	CThreadSocket* m_pSocket;
	
	RPointerArray<CReqData>		iReqArray;
	TTime	iTime;
	
	TBuf8<128>	iTradeUrl;
};

#endif // BLOCKPIPE_H
